package jMiiEditor.myavatareditor;

import java.util.EnumSet;
import utils.BinStuffs;
import jMiiEditor.mii.Mii;


public class MyAvavatarEditorAvatarId
{
    public enum Attrib {
        HIDE_SYSTEM_ID,
        HIDE_MII_CREATOR
    };
    private Mii mii;
    private final static byte[] byte0000 = {0,0,0,0};
    private EnumSet<Attrib> attribs;
    
    public MyAvavatarEditorAvatarId( Mii mii ) 
    {
        this( mii, null );
    }

    public MyAvavatarEditorAvatarId( 
            Mii             mii, 
            EnumSet<Attrib> attributes 
            ) 
    {
        this.mii = mii;
        
        if( attributes == null ) {
            this.attribs = EnumSet.of( Attrib.HIDE_SYSTEM_ID );
        }
        else {
            this.attribs = attributes;
        }
    }

//    public MyAvavatarEditorAvatarId( 
//            Mii mii, 
//            Attrib firstAttributes, 
//            Attrib...othersAttributes 
//            ) 
//    {
//        this.mii = mii;
//        this.attribs = EnumSet.of(firstAttributes,othersAttributes);
//    }
    
    public String getId()
    {
        Mii clone = new Mii( this.mii );
        
        if( attribs.contains( Attrib.HIDE_SYSTEM_ID )) {
            clone.setSystemId( byte0000 );
        }
        if( attribs.contains( Attrib.HIDE_MII_CREATOR )) {
            clone.setMiiCreator( "jMiiEditor" );
        }
        
        return getUnsafeId( clone );
    }
    
    public String getUnsafeId()
    {
        return getUnsafeId( mii );
    }
    
    public static String getUnsafeId( Mii mii )
    {
       byte[] bytes = mii.getBytesCopy();
       
       StringBuilder sb = new StringBuilder();
       
       for(byte b : bytes) {
           sb.append( BinStuffs.ubyteToHexString( b ) );
       }
       
       return sb.toString();
    }
    
}
